/*
 * @lc app=leetcode.cn id=66 lang=golang
 *
 * [66] 加一
 */

// @lc code=start
func plusOne(digits []int) []int {
	n := len(digits)
	res := make([]int, 0, n+1)
	tmp := 0
	for i := n - 1; i >= 0; i-- {
		if i == n-1 {
			digits[i], tmp = (digits[i]+1)%10, (digits[i]+1)/10

		} else {
			digits[i], tmp = (digits[i]+tmp)%10, (digits[i]+tmp)/10

		}

	}
	// fmt.Println(digits, tmp)
	if tmp != 0 {
		res = append(res, tmp)
		res = append(res, digits...)
		return res
	} else {
		return digits
	}
}

// @lc code=end
